package com.maolong.ackpro.controller;

import lombok.extern.slf4j.Slf4j;
import org.springframework.amqp.rabbit.connection.CorrelationData;
import org.springframework.amqp.rabbit.core.RabbitTemplate;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

@RestController
@Slf4j
public class AckController {
    @Autowired
    RabbitTemplate rabbitTemplate;
    @GetMapping("/ack")
    public String ack(@RequestParam String id) {
        CorrelationData correlationData = new CorrelationData();
        log.info("id:{}",id);
        rabbitTemplate.convertAndSend("ack_exchange","ack.ads",id,correlationData);
        return "ok";
    }

    @GetMapping("/ackBack")
    public String ackBack(@RequestParam String id) {
        log.info("id:{}",id);
        rabbitTemplate.convertAndSend("ack_exchange","aadck.ads",id);
        return "ok";
    }

    @GetMapping("/ackError")
    public String ackError(@RequestParam String id) {
        log.info("id:{}",id);
//        int i=1/0;
        rabbitTemplate.convertAndSend("ack_exchange","ack.ads",id);
        return "ok";
    }
}
